// 巡查计划
import store from '../index'
import useConfirm from '@/hooks/useConfirm'
import { TrafficIncidentModel } from '@/models'
const trafficIncidentModel = new TrafficIncidentModel()
const defaultState = () => {
    return {
        baseInfo: {}
    }
}

const getters = {}

const mutations = {
    setBaseInfo(state, baseInfo) {
        state.baseInfo = baseInfo
    }
}

const actions = {
    async saveOrUpdate({ commit }, data) {
        const res = await useConfirm({
            text: '是否确定保存表单',
            model: trafficIncidentModel,
            modelAction: 'saveOrUpdate',
            data
        })
        return res
    },
    async delete({ commit }, data) {
        const res = await useConfirm({
            text: '是否确定删除表单',
            model: trafficIncidentModel,
            modelAction: 'delete',
            data
        })
        return res
    },
    async detail({ commit }, { id, edit }) {
        console.log('edit :>> ', edit)
        try {
            store.commit('openLoading')
            const res = await trafficIncidentModel.detail({ id, isEdit: edit }, edit === false ? 'filter' : null)
            commit('setBaseInfo', res)
            return res
        } finally {
            store.commit('closeLoading')
        }
    }
}

export default {
    namespaced: true,
    state: defaultState(),
    getters,
    mutations,
    actions
}
